<template>
	<view class="about">
		<!-- <view v-if="hasLogin"> -->
		<!-- 导航 -->
		<!-- <u-navbar back-icon-color="#000000" title="意见反馈" title-color="#3F3F3F" :title-bold="true" :background="background"></u-navbar> -->
		<u-navbar back-text="意见反馈" :back-text-style="textStyle" back-icon-color="#000000" style="font-weight: bold;font-family: PingFang SC;"></u-navbar>
		<!-- end -->
		<view class="middle">
			<view class="icon">
				<view>
					我们非常重视用户反馈的信息
				</view>
				<view class="banben">
					您的反馈建议将会送达到bee到平台的CEO
				</view>
				<view>
					提前感谢，让我们一起建设一个美好的平台
				</view>
			</view>
			<view class="problem">
				<textarea class="p-20" placeholder="请输入您的反馈" maxlength="200" @input="descInput" v-model="desc" />
				<view class="num">{{remnant}}/200</view>
			</view>
			<view class="up">
				上传一些凭证(页面截图)等会更好哦~
			</view>
			<view class="choose">
				<view class="item" v-for="(item,index) in imgList" :key='index'>
					<image :src="item" mode="" ></image>
					<image class="no" src="../../static/icon/no.png" mode="" @click="del(index)"></image>
				</view>
				<view class="item" v-if="imgList.length < 6">
					<image src="../../static/icon/cau.png" mode="" @click="unphoto()"></image>
				</view>
			</view>
		</view>
		<view style="width: 642rpx;margin: 0 auto;margin-top: 90rpx;">
			<u-button type="warning" shape="circle" @click="submit()">提交反馈</u-button>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				background:{
					backgroundColor: '#fca800',
				},
				remnant:0,
				imgList:[],
				image_array:[],
				desc:''
			};
		},
		onShow() {
		},
		methods: {
			descInput(){
			   var txtVal = this.desc.length;
			   this.remnant = txtVal;
			 },
			unphoto(){
				var _this = this
				if (this.imgList.length < 6) {
					var _this = this;
					uni.chooseImage({
						count: 6,
						success: function(res) {
							var arr = [];
							for (var i in res.tempFilePaths) {
								_this.imgList.push(res.tempFilePaths[i]);
							}
							if (res.tempFilePaths.length > 6) {
								uni.showToast({
									icon: 'none',
									title: '最多上传6张图片',
									duration: 1000
								});
							}
						}
					});
				} else {
					uni.showToast({
						icon: 'none',
						title: '最多上传6张图片',
						duration: 1000
					});
				}
			},
			del(index) {
				uni.showModal({
					title: '提示',
					content: '是否要删除该图片',
					success: res => {
						if (res.confirm) {
							this.imgList.splice(index, 1);
						}
					}
				});
			},
			promotion(){
				var _this = this
				let opts = {
					way: true, //true JSON请求；false 表单请求
					method: 'post',
					url: '/userAdvice/add'
				};
				let data = {
					content:_this.desc,
					images:_this.image_array
				};
				_this.http.httpTokenRequest(opts, data).then(res => {
					console.log(res,"--")
					//打印请求返回的数据
					if (res.message == '成功') {
						_this.$refs.uToast.show({
							title: res.message,
							type: 'success',
						})
						setTimeout(function(){
							uni.navigateTo({
								url:'./ideaSuccess'
							})
						},500)
					} else {
						_this.$refs.uToast.show({
							title: res.message,
							type: 'error',
						})
						setTimeout(function(){
							uni.navigateTo({
								url:'./ideaFail'
							})
						},500)
					}
				});
			},
			submit(){
				var _this = this
				if(_this.imgList.length > 0){
					_this.image_array = []
					for (let k = 0; k < _this.imgList.length; k++) {
							uni.uploadFile({
								url: this.http.baseUrl +'/common/upload/batch',
								filePath: _this.imgList[k],
								name: 'file',
								fileType: 'image',
								success: (res) => {
									let url_href = JSON.parse(res.data).data[0];
									_this.image_array.push(url_href);
									if (_this.image_array.length == _this.imgList.length) {
										uni.hideLoading({
											title: '上传成功'
										})
										 _this.promotion()
									}
									
								},
								fail: (res) => {
									
								}
							});
					}
				}else{
					 _this.promotion()
				}
			}
		}
	};
</script>

<style scoped lang="scss">
	/* 导航 */
	
	.middle{
		padding: 60rpx 50rpx;
		}
		.icon{
			color: #3F3F3F;font-weight: 400;font-size: 30rpx;
		}
		.banben{
			padding: 14rpx 0;
		}
		.problem{
			padding: 30rpx 0;
		}
		.p-20{
			border: 1px solid #707070;
			padding: 14rpx 24rpx;
			font-size: 30rpx;color: #B9B9B9;
			font-family: PingFang SC;
			font-weight: 400;
			line-height: 21rpx;
			width: 610rpx;
		}
		.num{
			float: right;padding-top: 14rpx;
		}
		.up{
			font-size: 34rpx;
			font-family: PingFang SC;
			font-weight: 400;
			line-height: 24px;
			color: #3F3F3F;
			padding-top: 36rpx;
		}
		.choose{
			width: 100%;
			display: flex;
			justify-content: flex-start;
			flex-wrap: wrap;
			.item{
				width: 184rpx;
				height: 184rpx;
				position: relative;
				margin-right: 30rpx;
				margin-top: 20rpx;
				image{
					width: 100%;
					height: 100%;
				}
				.no{
					width: 30rpx;
					height: 30rpx;
					position: absolute;
					top:-15rpx;
					right: -15rpx;
				}
			}
		}
</style>
